package com.example.qxfw.dzzh.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.yj.YjfxdzLayeryz;
import com.example.qxfw.dzzh.mapper.YjfxdzLayeryzMapper;
import com.example.qxfw.dzzh.service.YjfxdzLayeryzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YjfxdzLayeryzServiceImpl implements YjfxdzLayeryzService {

    @Autowired
    private YjfxdzLayeryzMapper yjfxdzLayeryzMapper;

    @Override
    public List<YjfxdzLayeryz> listByFactorIndex(int factorIndex) {
        return yjfxdzLayeryzMapper.selectList(Wrappers.<YjfxdzLayeryz>lambdaQuery()
                .gt(YjfxdzLayeryz::getFactorIndex, factorIndex));
    }

    @Override
    public YjfxdzLayeryz save(YjfxdzLayeryz yjfxdzLayeryz) {
        int rows = yjfxdzLayeryzMapper.insert(yjfxdzLayeryz);
        return rows==0?null:yjfxdzLayeryz;
    }

    @Override
    public Integer delete(int factorIndex) {
        int rows = yjfxdzLayeryzMapper.delete(Wrappers.<YjfxdzLayeryz>lambdaQuery()
                .eq(YjfxdzLayeryz::getFactorIndex, factorIndex));
        return rows>0?factorIndex:-1;
    }

    @Override
    public Integer updateValue(int factorIndex, double value) {
        YjfxdzLayeryz yjfxdzLayeryz = new YjfxdzLayeryz();
        yjfxdzLayeryz.setValue(value);
        int rows = yjfxdzLayeryzMapper.update(yjfxdzLayeryz, Wrappers.<YjfxdzLayeryz>lambdaUpdate()
                .eq(YjfxdzLayeryz::getFactorIndex, factorIndex));
        return rows>0?factorIndex:-1;
    }
}
